#include "rclcpp/rclcpp.hpp"
#include "rclcpp/executors/multi_threaded_executor.hpp"
#include <sensor_msgs/msg/image.hpp>

#include "yolov8.h"

#include "image_subscribe.hpp"
int main(int argc, char **argv)
{
    const std::string modelPath = "/home/elf/Desktop/YOLOv8_RK3588_object_detect/model/weights/garbage_detect.rknn"; 
    // ros2
    rclcpp::init(argc,argv);

    // 初始化模型
    rknn_app_context_t rknn_app_ctx;
    memset(&rknn_app_ctx, 0, sizeof(rknn_app_context_t));

    init_post_process();

    int ret = init_yolov8_model(modelPath.c_str(), &rknn_app_ctx);

    if (ret != 0) {
        printf("模型初始化失败\n");
        return -1;
    }

    // 使用多线程执行器运行节点 
    auto node = std::make_shared<ImageSubscriberNode>(&rknn_app_ctx);
    rclcpp::executors::MultiThreadedExecutor executor;
    executor.add_node(node);
    RCLCPP_INFO(node->get_logger(), "ros2_garbage_detection_node节点已启动，使用多线程执行器.");
    executor.spin();

    rclcpp::shutdown();
    
    release_yolov8_model(&rknn_app_ctx);

    if (ret != 0) 
    {  
        printf("release_yolov8_model fail! ret=%d\n", ret);  
    }  

    deinit_post_process();

    return 0;
}